<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.MaterialDAO"%>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	request.setCharacterEncoding("utf-8");
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	MaterialDAO materialDao = (MaterialDAO)ctx.getBean("MaterialDAO");
	

	//System.out.println("==================>"+session.getAttribute("tid"));
	String name = request.getParameter("uname");
	if(name==null ||"请输入物资名称或单位名称".equalsIgnoreCase(name) || name=="请输入物资名称或单位名称"){
		name = "";
	}
	String message = "";
	
	String pagenem = request.getParameter("pageNo");
	int pn=0;
	if(pagenem==null || "".equals(pagenem)){
		pn=0;
	}else{
		pn = Integer.parseInt(pagenem);
	}
	//每页多少条
	int pageSize = 10;
	
	int tid = (Integer)session.getAttribute("tid");
	Object[][] ob = new Object[][]{};
	List listob = new ArrayList();
	if(name!=null){
		listob.add(new Object[]{"like","name",name});
		listob.add(new Object[]{"like","code",name});
		ob = new Object[][]{new Object[]{"or","",listob},new Object[]{"eq","isDelete",0},new Object[]{"eq","teamId",tid}};
	}

	Map map = materialDao.getMaterial(pn,pageSize,
	new String[][]{new String[]{"desc","date"}},
	ob,
	new String[][]{new String[]{"","id"},new String[]{"","name"},new String[]{"","code"},new String[]{"","company"}},
	new String[]{"",""}
	);
	//userDao.getMaterials(0, 0, new String[][]{new String[]{"desc","createDate"}}, new Object[][]{new Object[]{"eq","userId",userId},new Object[]{"eq","folderId",obj[0]},new Object[]{"eq","state","1"}}, new String[][]{new String[]{"","id"},new String[]{"","tag"},new String[]{"","MType"},new String[]{"","UType"},new String[]{"","t.createDate"},new String[]{"","path"}}, new String[]{"title","grope"});
	List li = (List) map.get("data");
	//System.out.println("========================>"+li.size());
	map.put("data",getListReMap(li));
	System.out.println("==============11111111111>>>>>"+name);
	//System.out.println(map.get("recordSize")+"==========="+map.get("pageTotal")+"=============="+map.get("pageSize"));
	//-----------------------------------分页-------------------------------------
		//List allnews=webNodeService.getSimpleNodeListByPnid(2,newsNodeid,0,999,1,0,true);
		//int pageCount= map.get("recordSize")%pageSize==0 ? allnews.size()/pageSize:allnews.size()/pageSize+1;
		int pageTotal = (Integer)map.get("pageTotal");
		int pageNo = (Integer)map.get("pageNo");
		List pageList=getPage(pageTotal,pageNo);
	//----------------------------------request.setAttribute()---------------------
		
		request.setAttribute("map",map);
		request.setAttribute("pages",pageList);
		//下拉菜单选中项
		if(name=="" || "请输入物资名称或单位名称".equals(name) || "".equals(name) || "请输入物资名称或单位名称"==name){
			request.setAttribute("mname","请输入物资名称或单位名称");
		}else{
			request.setAttribute("mname",name);
		}
		
		
		
		
		pageContext.forward("/vm/materials/materials_list.vm");
%>
<%!
	public List getListReMap(List list){
		List listmap = new ArrayList();
		if(list != null && list.size()>0){
		
			for(int i=0;i<list.size();i++){
			
				Map map = new HashMap();
				Object[] aa= (Object[]) list.get(i);
				
				System.out.println("=========>"+aa[0]+"====="+aa[1]+"===="+aa[2]);
				map.put("mid", aa[0]);
				map.put("mname", aa[1]);
				map.put("code", aa[2]);
				map.put("company", aa[3]);
				listmap.add(map);
			}
		}
		return listmap;
	}
%>